import FilenameParser
from xmlrpclib import ServerProxy

class RTorrentInterface(object):
  def __init__(self, xmlrpc_url):
    self.server = ServerProxy(xmlrpc_url)

  def active_downloads(self):
    eps = []
    filename_parser = FilenameParser.parser1()
    for hash_value in self.server.download_list('main'):
      filename = self.server.d.get_base_filename(hash_value)
      ep_info = filename_parser(filename)
      eps.append(ep_info)
    return eps

if __name__ == "__main__":
  interface = RTorrentInterface("http://mythtv/RPC2")
  print interface.active_downloads()
  #for method in interface.server.system.listMethods():
  #  print method
  #for download in interface.server.download_list('main'):
  #  print interface.server.d.get_base_filename(download)
